import {makeAction} from '../util'

//开启loading方法名
const SET_TOKEN = 'SET_TOKEN';
//关闭loading方法名
const CLEAR_TOKEN = 'CLEAR_TOKEN';

const state = {
    token: ''
};

const mutations = {
    //传进来一个state
    [SET_TOKEN](state, comm) {
        state.token = comm;
    },
    [CLEAR_TOKEN](state) {
        state.token = '';
        localStorage.removeItem('token')
    }
};

const actions = {
    //直接触发utils类中的makeaction方法  调用mutations
    set_token: makeAction(SET_TOKEN),
    clear_token: makeAction(CLEAR_TOKEN)
};

const getters = {
    //利用geter属性返回当前token的值
    gettoken(state) {
        return state.token
    }
};

export default {
    state,
    mutations,
    getters,
    actions
}
